package com.meow.action.front;

import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.meow.dao.entity.visa.Knowledge;
import com.meow.dao.mapper.visa.KnowledgeDao;
import com.meow.util.AjaxOut;
import com.meow.util.ExtLimit;

@Controller
@RequestMapping("/admin/front/FrontKnowledgeAction/")
public class FrontKnowledgeAction {

	private static final long serialVersionUID = -6934023626625535442L;
	
	private Logger logger = Logger.getLogger(FrontContinentAction.class);
	
	@Autowired
	private KnowledgeDao knowledgeDao;
	
	@RequestMapping("getKnowledge.action")
	public void getKnowledge(HttpServletRequest request, HttpServletResponse response) {
		try {
			String startStr = request.getParameter("start");
			String limitStr = request.getParameter("limit");
			
			int start = 0;
			int limit = 5;
			if(startStr != null && !startStr.trim().equals("")) 
				start = Integer.parseInt(startStr);
			if(limitStr != null && !limitStr.trim().equals("")) 
				limit = Integer.parseInt(limitStr);
			
			ExtLimit limitEty = new ExtLimit();
			limitEty.setStart(start);
			limitEty.setLimit(limit);
			limitEty.setSort("displayOrder");
			limitEty.setDir("DESC");
			
			Knowledge knowledgeEty = new Knowledge();
			knowledgeEty.setExtLimit(limitEty);
			List knList = knowledgeDao.selectByLimit(knowledgeEty);
			AjaxOut.responseJSonGrid(response, knList, knList.size(), new SimpleDateFormat("yyyy-MM-dd"));
		}
		catch (Exception e) {
			logger.error("前台取学识错误！", e);
		}
	}
	
}
